%%%===================================================================
%%% 功能
%%%===================================================================

-define(EH_GET(Path, Handler), #eh_route{method = <<"GET">>, path = Path, handler = Handler, middles = []}).
-define(EH_GET(Path, Handler, Middle), #eh_route{method = <<"GET">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_POST(Path, Handler), #eh_route{method = <<"POST">>, path = Path, handler = Handler, middles = []}).
-define(EH_POST(Path, Handler, Middle), #eh_route{method = <<"POST">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_PUT(Path, Handler), #eh_route{method = <<"PUT">>, path = Path, handler = Handler, middles = []}).
-define(EH_PUT(Path, Handler, Middle), #eh_route{method = <<"PUT">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_DELETE(Path, Handler), #eh_route{method = <<"DELETE">>, path = Path, handler = Handler, middles = []}).
-define(EH_DELETE(Path, Handler, Middle), #eh_route{method = <<"DELETE">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_PATCH(Path, Handler), #eh_route{method = <<"PATCH">>, path = Path, handler = Handler, middles = []}).
-define(EH_PATCH(Path, Handler, Middle), #eh_route{method = <<"PATCH">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_OPTIONS(Path, Handler), #eh_route{method = <<"OPTIONS">>, path = Path, handler = Handler, middles = []}).
-define(EH_OPTIONS(Path, Handler, Middle), #eh_route{method = <<"OPTIONS">>, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_ALL(Path, Handler), #eh_route{method = all, path = Path, handler = Handler, middles = []}).
-define(EH_ALL(Path, Handler, Middle), #eh_route{method = all, path = Path, handler = Handler, middles = ehttp_util:fix_middle(Middle)}).

-define(EH_GROUP(Path, Items), #eh_group{path = Path, items = Items, middles = []}).
-define(EH_GROUP(Path, Items, Middle), #eh_group{path = Path, items = Items, middles = ehttp_util:fix_middle(Middle)}).


-record(eh_route, {
    method :: bitstring()
    ,path :: string()
    ,handler :: fun() | {Module :: atom(), Function :: atom()}
    ,middles :: [atom()]
}).

-record(eh_group, {
    path :: string()
    ,items :: list()
    ,middles :: [atom()]
}).


%%%===================================================================
%%% 日志
%%%===================================================================

-define(EH_ECHO(Format),            catch ehttp_logger:echo(Format, [])).
-define(EH_ECHO(Format, Args),      catch ehttp_logger:echo(Format, Args)).
-define(EH_INFO(Format),            catch ehttp_logger:info(Format, [], ?MODULE, ?LINE)).   % 重要日志
-define(EH_INFO(Format, Args),      catch ehttp_logger:info(Format, Args, ?MODULE, ?LINE)). % 重要日志
-define(EH_ERR(Format),             catch ehttp_logger:error(Format, [], ?MODULE, ?LINE)).  % 错误日志
-define(EH_ERR(Format, Args),       catch ehttp_logger:error(Format, Args, ?MODULE, ?LINE)).% 错误日志
